/*
 * Copyright (c) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http:  // www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include "cashdevice_client.h"
#include "hilog_wrapper.h"

namespace SwanLink {
namespace Finance {
std::vector<DevAccess> CashDeviceClient::GetSupportAccess()
{
    int ret = Connect();
    if (ret != ERR_OK) {
        COMMON_HILOGE(COMMON_JS_NAPI, "GetSupportAccess failed");
        return {};
    }
    return Proxy()->GetSupportAccess();
}

int CashDeviceClient::Open(const std::string& name, const Transport& trans)
{
    int ret = Connect();
    if (ret != ERR_OK) {
        COMMON_HILOGE(COMMON_JS_NAPI, "Open failed");
        return -1;
    }
    return Proxy()->Open(name, trans);
}

int CashDeviceClient::Close(int handle)
{
    int ret = Connect();
    if (ret != ERR_OK) {
        COMMON_HILOGE(COMMON_JS_NAPI, "Close failed");
        return -1;
    }
    return Proxy()->Close(handle);
}

int CashDeviceClient::QueryStatus(int handle, int module, char *err)
{
    int ret = Connect();
    if (ret != ERR_OK) {
        COMMON_HILOGE(COMMON_JS_NAPI, "QueryStatus failed");
        return -1;
    }
    return Proxy()->QueryStatus(handle, module, err);
}

int CashDeviceClient::Reset(int handle)
{
    int ret = Connect();
    if (ret != ERR_OK) {
        COMMON_HILOGE(COMMON_JS_NAPI, "Reset failed");
        return -1;
    }
    return Proxy()->Reset(handle);
}

}  // namespace Finance
}  // namespace SwanLink
